package com.huawei.petSystemdemo;

import android.app.IntentService;
import android.app.Notification;
import android.app.NotificationManager;
import android.content.Intent;

import androidx.core.app.NotificationCompat;

/**
 *
 * Android studio的消息推送
 * An {@link IntentService} subclass for handling asynchronous task requests in
 * a service on a separate handler thread.
 * <p>
 * TODO: Customize class - update intent actions and extra parameters.
 */
public class DelayMessageService extends IntentService {

    public static final int ID = 5000;

    public static  final String EXTRA_MESSAGE="message";
    public DelayMessageService() {
        super("DelayMessageService");
    }

    @Override
    protected void onHandleIntent(Intent intent) {
     synchronized (this){
         try {
             wait(3000);
         }catch (InterruptedException e) {
             e.printStackTrace();
         }
     }
        String text = intent.getStringExtra(EXTRA_MESSAGE);

        NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
                .setSmallIcon(android.R.drawable.sym_def_app_icon)//
                .setContentTitle(getString(R.string.SuccessMessageTitle))
                .setContentText(text) 
                .setPriority(NotificationCompat.PRIORITY_HIGH)
                .setVibrate(new long[]{0,1000})
                .setAutoCancel(true);//用户点击后消失




        NotificationManager notificationManager=(NotificationManager)getSystemService(NOTIFICATION_SERVICE);
        notificationManager.notify(ID,builder.build());
    }

}